import {useRoute,useRouter} from 'vue-router';
import useStore from "@/store/modules/user"

// 白名单路由
const whileRoutes = ["/login"]

const routes = useRouter()
routes.getRoutes().forEach((to,from,next) => {
    // 每次点击路由都要判断是否是登陆状态
    if (useStore.getters.getToken) {
        if (to.path === "/login") {
            next("/")
        } else {
            next()
        }
        return;
    } else {
        // 如果要去的路由在白名单内则直接放行，否则跳转到登录页
        if (whileRoutes.includes(to.path)) {
            next()
        } else {
            next("/login")
        }
    }
})
